home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Basic Layout Sample ƒ / QDGX shell misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  5.0 KB  |  237 lines  |  [TEXT/KAHL]

  1. /**\
  2. |**| =====================================================================
  3. |**|
  4. |**|    QDGX shell misc.c
  5. |**|
  6. |**|    This file contains utility and menu handling routines for
  7. |**|    the QuickDraw GX shell program.
  8. |**|
  9. |**|    ©1992-1994  Apple Computer, Inc.
  10. |**|    All rights reserved.
  11. |**|
  12. |**| =====================================================================
  13. \**/
  14.  
  15.  
  16. #include "QDGX shell.h"
  17. #include "layout routines.h"
  18. #include "layout library.h"
  19. #include "font menu library.h"
  20.  
  21.  
  22.  
  23. /**\
  24. |**| ---------------------------------------------------------------------
  25. |**| DoMenuCommand()
  26. |**| This routine handles the dispatching of our menu requests.
  27. |**| ---------------------------------------------------------------------
  28. \**/
  29. void DoMenuCommand (long menuResult)
  30. {
  31.     short                menuID;
  32.     short                menuItem;
  33.     Str255                daName;
  34.     OSErr                err;
  35.     gxDialogResult        result;
  36.     
  37.     menuID = menuResult >>16;
  38.     menuItem = menuResult & 0x0000ffff;
  39.     
  40.     switch (menuID)
  41.     {
  42.         case mApple:
  43.             switch (menuItem)
  44.             {
  45.                 case iAbout:                /* display About box */
  46.                     NoteAlert(rAboutBoxID,nil);
  47.                     break;
  48.                 
  49.                 default:                    /* handle DA selection */
  50.                     GetItem(GetMHandle(mApple), menuItem, daName);
  51.                     OpenDeskAcc(daName);
  52.                     break;
  53.             }
  54.             break;
  55.  
  56.  
  57.         case mFile:
  58.             switch (menuItem)
  59.             {                        
  60.                 case iNew:                    /* create new window */
  61.                     err = DoCreateNew();
  62.                     break;
  63.                                             
  64.                 case iOpen:                    /* open saved window */
  65.                     break;
  66.                                             
  67.                 case iClose:                /* close front window */
  68.                     DoDispose(FrontWindow());
  69.                     break;
  70.                                             
  71.                 case iSave:                    /* save front window */
  72.                     break;
  73.                                             
  74.                 case iPageSetup:            /* perform page setup */
  75.                     HiliteMenu(0);
  76.                     err = DoFormat(FrontWindow(), &result);
  77.                     break;
  78.                                             
  79.                 case iPrintOne:                /* perform print-one */
  80.                     err = DoPrintOne(FrontWindow());
  81.                     break;
  82.                     
  83.                 case iPrint:                /* perform print */
  84.                     HiliteMenu(0);
  85.                     err = DoPrinting(FrontWindow());
  86.                     break;
  87.  
  88.                 case iQuit:
  89.                     gQuitting = true;
  90.                     break;
  91.             }
  92.             break;
  93.  
  94.  
  95.         case mEdit:
  96.             switch(menuItem)
  97.             {
  98.                 case iCut:
  99.                     LayoutEditCut( GetDocLEHandle(FrontWindow()) );
  100.                     break;
  101.                 
  102.                 case iCopy:
  103.                     LayoutEditCopy( GetDocLEHandle(FrontWindow()) );
  104.                     break;
  105.                 
  106.                 case iPaste:
  107.                     LayoutEditPaste( GetDocLEHandle(FrontWindow()) );
  108.                     break;
  109.                 
  110.                 case iClear:
  111.                     LayoutEditClear( GetDocLEHandle(FrontWindow()) );
  112.                     break;
  113.             }
  114.             break;
  115.             
  116.         case nestingMenuID:
  117.             switch (menuItem)
  118.             {
  119.                 case nestCommand:
  120.                     LayoutEditIncrementLevel( GetDocLEHandle(FrontWindow()) );
  121.                     break;
  122.                     
  123.                 case unnestCommand:
  124.                     LayoutEditDecrementLevel( GetDocLEHandle(FrontWindow()) );
  125.                     break;
  126.                 
  127.                 default:
  128.                     LayoutEditSetLevel( GetDocLEHandle(FrontWindow()), menuItem - zeroCommand);
  129.                     break;
  130.             }
  131.             break;
  132.             
  133.         case fontMenuID:
  134.         default:
  135.             {
  136.                 boolean ok;
  137.                 gxStyle menuStyle;
  138.                 static short first = true;
  139.                 
  140.                 menuStyle = GXNewStyle();
  141.                 ok = DoHierFontMenuCommandStyle(menuResult, fontMenuID, menuStyle, noMatching);
  142.                 if (ok)
  143.                 {
  144.                     GXSetStyleTextSize(menuStyle, ff(30));
  145.                     LayoutEditSetStyle( GetDocLEHandle(FrontWindow()), menuStyle);
  146.                 }
  147.                 GXDisposeStyle(menuStyle);
  148.  
  149.             }
  150.             break;
  151.                 
  152.     }
  153.     HiliteMenu(0);
  154. }
  155.  
  156.  
  157. /**\
  158. |**| ---------------------------------------------------------------------
  159. |**| GetDocShape()
  160. |**| This utility routine returns the page contents shape
  161. |**| attached to a window's document.
  162. |**| ---------------------------------------------------------------------
  163. \**/
  164. gxShape GetDocShape (WindowPtr wind)
  165. {
  166.     TH_Doc    doc;
  167.     gxShape    docPage = nil;
  168.  
  169.     if ( wind != NULL )
  170.     {
  171.         doc = (TH_Doc) GetWRefCon(wind);
  172.         docPage = (*doc)->docPage;
  173.     }
  174.     
  175.     return docPage;
  176. }
  177.  
  178.  
  179. /**\
  180. |**| ---------------------------------------------------------------------
  181. |**| GetDocJob()
  182. |**| This utility routine returns the print job attached to a window's document.
  183. |**| ---------------------------------------------------------------------
  184. \**/
  185. gxJob GetDocJob (WindowPtr wind)
  186. {
  187.     TH_Doc    doc;
  188.     gxJob        docJob = nil;
  189.  
  190.     if ( wind != NULL )
  191.     {
  192.         doc = (TH_Doc) GetWRefCon(wind);
  193.         docJob = (*doc)->docJob;
  194.     }
  195.     
  196.     return docJob;
  197. }
  198.  
  199.  
  200. /**\
  201. |**| ---------------------------------------------------------------------
  202. |**| GetDocLEHandle()
  203. |**| This utility routine returns the current LayoutEditHandle structure
  204. |**| attached to a window's document.
  205. |**| ---------------------------------------------------------------------
  206. \**/
  207. LayoutEditHandle GetDocLEHandle (WindowPtr wind)
  208. {
  209.     TH_Doc    doc;
  210.     LayoutEditHandle    docLEHandle = nil;
  211.  
  212.     if ( wind != NULL )
  213.     {
  214.         doc = (TH_Doc) GetWRefCon(wind);
  215.         docLEHandle = (*doc)->docLEHandle;
  216.     }
  217.     
  218.     return docLEHandle;
  219. }
  220.  
  221.  
  222. /**\
  223. |**| ---------------------------------------------------------------------
  224. |**| MyStrLength()
  225. |**| This function takes the length of a C-style string quickly without
  226. |**| requiring an ANSI library to be linked in.
  227. |**| ---------------------------------------------------------------------
  228. \**/
  229. short MyStrLength (char *s)
  230. {
  231.     short len;
  232.  
  233.     for (len = 0; *s++ != 0; len++) ;
  234.     return len;
  235. }
  236.  
  237.